import {Component, Input, ViewChild} from '@angular/core';
import {Category} from "../../../models/Category";
import {CategoryProvider} from "../../../providers/category";
import {Content, NavController} from "ionic-angular";
import {HomePage} from "../../pages/home/home";
import {ShoppingCartPage} from "../../pages/shopping-cart/shopping-cart";
import {KitProvider} from "../../../core/foundations/KitProvider";
import {DishProvider} from "../../../providers/DishProvider";
import {MenuPage} from "../../pages/menu/menu";
import {CartProvider} from "../../../providers/cartProvider";
import {CustomerAlertPage} from "../../pages/alert/alert";
/**
 * Generated class for the CustomerHeaderComponent component.
 *
 * See https://angular.io/docs/ts/latest/api/core/index/ComponentMetadata-class.html
 * for more info on Angular Components.
 */
@Component({
  selector: 'customer-header',
  templateUrl: 'customer-header.html'
})
export class CustomerHeaderComponent {
  @ViewChild(Content) content: Content;

  @Input() showCate: boolean;
  keywords: string;
  categories: Category[];
  store: any;
  Table_ID = '11A';
  show = true;
  constructor(public cateProd: CategoryProvider,
              public nav: NavController,
              public kit: KitProvider,
              public cartPro: CartProvider,
              public dishProd: DishProvider,) {
    this.keywords = localStorage.getItem('keywords');
    this.cateProd.getCategories().subscribe(categories => {
      this.categories = categories
    });
    this.cartPro.getTables().subscribe(Stores => {
      this.store = Stores;
      console.log(this.store)
    });
    if (this.cartPro.Table_ID() != null) {
      this.show=false;
      this.Table_ID = this.cartPro.Table_ID();
      console.log(this.Table_ID);
    }
  }

  search(ev) {
    // set val to the value of the ev target
    let val = ev.target.value;
    // if the value is an empty string don't filter the items
    if (val && val.trim() != '') {
      console.log('header', val);
      localStorage.setItem("keywords", val);
      setTimeout(3000);
      this.nav.setRoot(HomePage, {keywords: val});
    }

  }

  onClear(event) {
    localStorage.setItem("keywords", null);
  }

  openModel() {
    this.nav.push(CustomerAlertPage);
  }
  showCart() {
    this.nav.push(ShoppingCartPage);
  }

  showList(name: string) {
    this.nav.setRoot(HomePage, {category: name});
  }

  showAll() {
    this.nav.pop(MenuPage);
  }
}
